/*
 * @Author: sbotlp
 * @Email: sbotlp@sina.com
 * @Date: 2019-11-06 23:03:37
 * @LastEditTime: 2019-11-06 23:39:18
 * @Description: http://www.sbotlp.com.cn
 */
(function(window) {
  var jQuery = function(selector) {
    return new jQuery.fn.init(selector);
  }
  // 为何要把原型方法放在jQuery.fn??????
  // 答案：应为可扩展性，插件机制；方便扩展或者插入新的放方法，使得库更加灵活多变；
  // 将插件扩展统一到$.fu.xxx 这个接口，方便使用；
  jQuery.fn={
    css: function (key, value) {
      var i =0;
      for (i = 0; i < this.length; i++) {
        this[i].setAttribute('style', `${key}:${value}`);
      }
    },
    html: function() {
      return document.querySelector(this.selector).innerHTML;
    }
  }
  var init = jQuery.fn.init = function (selector) {
    var slice = Array.prototype.slice;
    var dom =slice.call(document.querySelectorAll(selector));
    var i,len = dom? dom.length: 0;
    for (i=0;i<len;i++) {
      this[i]=dom[i];
    }
    this.length=len;
    this.selector = selector||'';
  }
  init.prototype = jQuery.fn;
  window.$=jQuery;
})(window)